//
//  LRRetweetStatusV.swift
//  WeiboX
//
//  Created by admin on 05/12/2016.
//  Copyright © 2016 iOS_Objective-C. All rights reserved.
//

import UIKit
import SnapKit

class LRStatusRetweetV: UIView {
	
	var selfBottomConstraint: Constraint?
	
	var statusVM: LRStatusVM? {
		didSet {
			content.text = statusVM?.retweetStatus
			
			selfBottomConstraint?.deactivate()
			if let picUrls = statusVM?.status?.retweeted_status?.pic_urls, picUrls.count > 0 {
				// 有图片
				statusPic.isHidden = false
				
				// 更新约束
				self.snp.makeConstraints({ (make) in
					selfBottomConstraint = make.bottom.equalTo(statusPic).offset(StatusItemMargin).constraint
				})
				
				statusPic.picUrls = picUrls
			} else {
				// 没有配图
				statusPic.isHidden = true
				
				// 更新约束
				self.snp.makeConstraints({ (make) in
					selfBottomConstraint = make.bottom.equalTo(content).offset(StatusItemMargin).constraint
				})
				
//				statusPic.picUrls = statusVM?.status?.retweeted_status?.pic_urls
			}
		}
	}
	
	private lazy var statusPic: LRStatusPicCollectionV = LRStatusPicCollectionV()
	
	private lazy var content: UILabel = {
		let label = UILabel(fontSize: 14, textColor: UIColor.gray)
		label.numberOfLines = 0
		label.text = "测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text 测试文本 test text"
		
		return label
	}()

	override init(frame: CGRect) {
		super.init(frame: frame)
		
		setupUI()
	}
	
	required init?(coder aDecoder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
	
	func setupUI() {
		
		backgroundColor = UIColor.init(white: 0.95, alpha: 1)
		
		addSubview(content)
		addSubview(statusPic)
		
		content.snp.makeConstraints { (make) in
			make.top.leading.equalToSuperview().offset(StatusItemMargin)
			make.trailing.equalToSuperview().offset(-StatusItemMargin)
		}
		
		statusPic.snp.makeConstraints { (make) in
//			 MARK: - 必须指定 size
			make.top.equalTo(content.snp.bottom).offset(StatusItemMargin)
			make.leading.equalTo(content)
		}
		
		self.snp.makeConstraints { (make) in
			selfBottomConstraint = make.bottom.equalTo(statusPic).offset(StatusItemMargin).constraint
		}
	}
}
